package com.act.web;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.act.domain.AttendanceManagement;
import com.act.dto.Response;
import com.act.service.api.IAttendanceManagementService;



@RestController
@RequestMapping("am")
public class AttendanceManagementController {
	@Resource
	private  IAttendanceManagementService iAttendanceManagementService;
	
	
//    @RequestMapping(value = "/createattendance",method = RequestMethod.POST)
//	    public ModelAndView createAttendance(AttendanceManagement attendanceManagement) {
//    		iAttendanceManagementService.add(attendanceManagement);
//    		ModelAndView maView=new ModelAndView();
//    		maView.setViewName("user/register");
//    		maView.addObject("am",attendanceManagement);
//    	
//          return maView;
//	}
	
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Response add(AttendanceManagement attendanceManagement) {
    	 try {
    			iAttendanceManagementService.add(attendanceManagement);
             return Response.success();
         } catch (Exception e) {
           
             return Response.fail();
         }
	
    }
    
//    @RequestMapping(value="/getAllList",method = RequestMethod.GET)
//        public ModelAndView getAllList() {
//    		List<AttendanceManagement> amlist=iAttendanceManagementService.getAllList();
//    		ModelAndView maView=new ModelAndView();
//    		maView.setViewName("user/register");
//    		maView.addObject("amlist",amlist);
//    	
//          return maView;
//	}
    
    @RequestMapping(value="/get",method=RequestMethod.GET)
    public @ResponseBody List<AttendanceManagement> getAll(){
    	List<AttendanceManagement> amlist=iAttendanceManagementService.getAllList();
        return amlist;
    }
    

    
    @RequestMapping(value="/getListById/{id}")
    @ResponseBody
    public ModelAndView getAttendanceListByevaluationId(@PathVariable int id) {
		List<AttendanceManagement> amlist=iAttendanceManagementService.getAttendanceListByevaluationId(id);
		ModelAndView maView=new ModelAndView();
		maView.setViewName("user/register");
		maView.addObject("amlist",amlist);
		return maView;
    }
}
